import axios from '@/utils/request'

/**
 * 获取新闻详情
 *
 * @export
 * @param {*} artId 文章Id
 * @return {*}
 */
export function getArtilceDetail(artId) {
  return axios({ url: '/v1_0/articles/' + artId })
}

/**
 * 关注作者
 *
 * @export
 * @param {*} target 关注的用户的id
 * @return {*}
 */
export function followUser(target) {
  return axios({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

/**
 * 取消关注作者
 *
 * @export
 * @param {*} target 关注的用户的id
 * @return {*}
 */
export function unFollowUser(target) {
  return axios({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + target
  })
}

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
* 添加点赞
* @param {*} id 文章编号
*/
export const addLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
* 取消不喜欢
* @param {*} id 文章编号
*/
export const deleteDisLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
* 添加不喜欢
* @param {*} id 文章编号
*/
export const addDisLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 获取对文章的评论
 *
 * @export
 * @param {*} source 文章id
 * @param {*} offset 偏移量 获取第几页数据
 * @return {*}
 */

export const getArtilceCommon = (source, offset) => {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      limit: 10
    }
  })
}

/**
 * 对文章进行发表评论
 *
 * @export
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @return {*}
 */
export const addArticleCommon = (target, content) => {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target,
      content
    }
  })
}
/**
 * 对评论进行点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export const likeCommon = (target) => {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target
    }
  })
}
/**
 * 对评论进行取消点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export const unLikeCommon = (target) => {
  return axios({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + target

  })
}
/**
 * 获取评论回复的评论
 *
 * @export
 * @param {*} source 评论id
 * @param {*} offset 偏移量 获取第几页数据
 * @return {*}
 */
export const getCommonToCommon = (source, offset) => {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })
}
/**
 * 对评论进行发表评论
 *
 * @export
 * @param {*} artId 文章id
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @return {*}
 */
export const addCommonToCommon = (artId, target, content) => {
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      art_id: artId,
      target,
      content
    }
  })
}
